#ifndef GEOMETRY_CUBE_H
#define GEOMETRY_CUBE_H

#include "vector3d.h"
#include "vertex3D.h"
#include "geometry.h"
#include "math3d.h"

#include <QList>
#include <QDebug>

/**
 * 王诗阳专属立方体
 * @brief 王诗阳专属立方体
 */
class WSYCube : public Geometry {
public:
    WSYCube(double length, double width, double height) {
        this->setType("object");
        this->initialize();
        resetVariables(length, width, height);
    }
    //~Geometry_Cube();

    virtual void resetVariables(double length, double width, double height) {
        //qDebug() << "大追踪0 ";
        this->length = length;
        this->width = width;
        this->height = height;
        this->generate();
    }

private:
    double length, width, height;
    virtual void pushSingleRectangle(Vertex3D *vA, Vertex3D *vB, Vertex3D *vC, Vertex3D *vD) {
        this->pushSinglePlane(vA, vB, vC);
        this->pushSinglePlane(vC, vD, vA);
    }
    //生成几何体
    virtual void generate() {
        double halfLength = this->length / 2;
        double halfWidth = this->width / 2;
        double z = this->height / 2;

        Vertex3D *A0 = new Vertex3D(halfLength, halfWidth, -z);
        Vertex3D *B0 = new Vertex3D(-halfLength, halfWidth, -z);
        Vertex3D *C0 = new Vertex3D(-halfLength, -halfWidth, -z);
        Vertex3D *D0 = new Vertex3D(halfLength, -halfWidth, -z);

        Vector3D *heightDirection = new Vector3D(0, 0, this->height);
        Vertex3D *A1 = A0->addVectors(heightDirection),
            *B1 = B0->addVectors(heightDirection),
            *C1 = C0->addVectors(heightDirection),
            *D1 = D0->addVectors(heightDirection);

        A1->printSinglePoint("A1");
        B1->printSinglePoint("B1");
        C1->printSinglePoint("C1");
        D1->printSinglePoint("D1");

        QList<Vertex3D*> *vertices0 = new QList<Vertex3D*>();
        vertices0->push_back(A0);
        vertices0->push_back(B0);
        vertices0->push_back(C0);
        vertices0->push_back(D0);

        QList<Vertex3D*> *vertices1 = new QList<Vertex3D*>();
        vertices1->push_back(A1);
        vertices1->push_back(B1);
        vertices1->push_back(C1);
        vertices1->push_back(D1);


        //中间部位
        for (int i = 0; i < vertices0->count(); i++) {
            Vertex3D *v0 = vertices0->at(i);
            Vertex3D *vA = v0, *vB = vertices0->at((i + 1) % vertices0->count()),
            *vC = vertices1->at((i + 1) % vertices1->count()), *vD = vertices1->at(i);

            this->pushSingleRectangle(vA, vB, vC, vD);
        }

        this->pushSingleRectangle(D0, C0, B0, A0); //底部部位
        this->pushSingleRectangle(A1, B1, C1, D1); //顶部部位

        this->generateBufferOfObject();
    }
};

#endif // GEOMETRY_CUBE_H
